package com.esunny.resourcevisualization.util;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

/**
 * @author ：李先生
 * @date ：Created in 2020/7/18 15:16
 * @description： Cookie相关的工具类
 * @modified By：
 * @version: $
 */
public class CookieUtil {

    private CookieUtil(){}

    public static String getValue(HttpServletRequest request, String name) {
        if (request == null || name == null) {
            throw new IllegalArgumentException("参数为空");
        }
        //通过request获取cookie数组
        Cookie[] cookies = request.getCookies();
        if (cookies != null) {
            for (Cookie cookie : cookies) {
                if (cookie.getName().equals(name)) {
                    return cookie.getValue();
                }
            }
        }

        return null;
    }
}
